<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
  import LoginForm from '_c/login-form'
  import {mapActions} from 'vuex'

  export default {
    components: {
      LoginForm
    },
    data() {
      return {
        webToken: {
          name: 'super_admin',
          user_id: '1',
          access: ['super_admin', 'admin'],
          token: 'super_admin',
          avator: 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
        }
      }
    },
    methods: {
      getPermission() {
        var n = new Notification('登陆更新提醒', {
          body: '登陆成功！',
          tag: '林安康',
          icon: 'http://blog.gdfengshuo.com/images/avatar.jpg',
          requireInteraction: false,
          data: {
            url: 'http://baidu.com'
          }
        })
        n.onclick = function () {
          window.open(n.data.url, '_blank');      // 打开网址
          n.close();                              // 并且关闭通知
        }
      },
      handleSubmit({userName, password}) {
        // this.$axios.post('userLogin/moreHandle', {username: userName, password: password}).then(p => {
        //   console.log(p)
        //   if (p.data.result.length > 0) {
        //     this.$Message.info('登陆成功');
        //     this.getPermission();
        //     localStorage.setItem('userInfo', JSON.stringify(this.webToken));
        //     this.$router.push({
        //       name: this.$config.homeName
        //     })
        //   } else {
        //     this.$Message.info('登陆失败');
        //   }
        // })

        this.$router.push({
          name: this.$config.homeName
        })
      },
      getWebToken() {
        this.$axios.get('userLogin/getToken').then((p) => {
          localStorage.setItem('Authorization', p.data.result)
        })
        this.$store.dispatch('setUserToken', this.webToken).then(() => {
        });
      },
    },
    created() {
      Notification.requestPermission().then(function (permission) {
        if (permission === 'granted') {
          console.log('用户允许通知');
        } else if (permission === 'denied') {
          console.log('用户拒绝通知');
        }
      });
      // this.getWebToken();
    }
  }
</script>

<style>

</style>
